package cn.anecansaitin.whimsy.test.explayer.layer;

import cn.anecansaitin.whimsy.test.explayer.GeoPlayer;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import software.bernie.geckolib.cache.object.GeoBone;
import software.bernie.geckolib.core.animatable.GeoAnimatable;
import software.bernie.geckolib.renderer.GeoRenderer;
import software.bernie.geckolib.renderer.layer.GeoRenderLayer;

public class PlayerLayer<T extends GeoAnimatable> extends GeoRenderLayer<GeoPlayer> {
    private final PlayerLayerRender<T> layerRender;
    private final String boneName;

    public PlayerLayer(GeoRenderer<GeoPlayer> renderer, PlayerLayerRender<T> render, String boneName) {
        super(renderer);
        this.layerRender = render;
        this.boneName = boneName;
    }

    @Override
    public void renderForBone(PoseStack poseStack, GeoPlayer animatable, GeoBone bone, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, float partialTick, int packedLight, int packedOverlay) {
        if (!bone.getName().equals(boneName)) {
            return;
        }

        poseStack.pushPose();
        poseStack.translate(-0.15, -0.0725, -0.5);
        layerRender.render(poseStack, layerRender.getAnimatable(), bufferSource, renderType, buffer, packedLight);
        bufferSource.getBuffer(renderType);
        poseStack.popPose();
    }
}
